import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.compiler.CompilationException;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;

import java.io.*;

public class MyActionClass2 extends AnAction {

        @Override
        public void actionPerformed(AnActionEvent e) {
            init(e);
        }

    /**
     * 初始化处理
     * @param e
     */
    private void init(AnActionEvent e) {

        //根据响应的事件 获取到当前事件所在的项目、编辑器、文件、
        Project project = e.getProject();
        Editor editor = e.getData(LangDataKeys.EDITOR);
        assert editor != null;
        final Document document = editor.getDocument();
        final StringBuilder stringBuffer = new StringBuilder().append("插入的数字");
        //写入到编辑器内容
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                document.insertString(0,stringBuffer.toString());
            }
        };

        //写入编辑器
        WriteCommandAction.runWriteCommandAction(project,runnable);
    }





}

